package com.skylin.mysell.converter;

import com.google.common.collect.Lists;
import com.skylin.mysell.dto.OrderDTO;
import com.skylin.mysell.entities.OrderDetail;
import com.skylin.mysell.form.OrderForm;

import java.util.ArrayList;

/**
 * @author quanlinlin on 2019/1/6 17:41.
 * @version 1.0
 */
public class OrderForm2OrderDTOConverter {
    public static OrderDTO convert(OrderForm orderForm) {
        OrderDTO orderDTO = new OrderDTO();
        orderDTO.setBuyerName(orderForm.getName());
        orderDTO.setBuyerPhone(orderForm.getPhone());
        orderDTO.setBuyerOpenid(orderForm.getOpenid());
        orderDTO.setBuyerAddress(orderForm.getAddress());

        ArrayList<OrderDetail> orderDetailArrayList = Lists.newArrayList();
        //Gson gson = new Gson();
        //orderDetailArrayList = gson.fromJson(orderForm.getItems(), new TypeToken<List<OrderDetail>>() {
        //}.getType());
        //orderDTO.setOrderDetailList(orderDetailArrayList);
        orderDTO.setOrderDetailList(orderForm.getItems());
        return orderDTO;
    }
}
